package com.example.zwh.computershop;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;

import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;



public class BottomAnimDialog extends Dialog implements View.OnClickListener{

    Context context;
    int layoutResID;
    int[] listenedItems;

    public BottomAnimDialog(Context context, int layoutResID, int[] listenedItems) {
        super(context, R.style.BottomDialog);
        this.context = context;
        this.layoutResID = layoutResID;
        this.listenedItems = listenedItems;
    }
    public BottomAnimDialog( Context context) {
        super(context);
    }

    public BottomAnimDialog( Context context, int themeResId) {
        super(context, themeResId);
    }

    protected BottomAnimDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Window window = getWindow();
        window.setGravity(Gravity.BOTTOM);
        window.setWindowAnimations(R.style.BottomDialogAnimation);
        setContentView(layoutResID);

        setCanceledOnTouchOutside(true);
        for (int id : listenedItems) {
            findViewById(id).setOnClickListener(this);
        }
    }

    private OnCenterItemClickListener listener;
    public interface OnCenterItemClickListener {
        void OnCenterItemClick(BottomAnimDialog dialog, View view);
    }
    public void setOnCenterItemClickListener(OnCenterItemClickListener listener) {
        this.listener = listener;
    }

    @Override
    public void onClick(View view) {
        dismiss();//注意：我在这里加了这句话，表示只要按任何一个控件的id,弹窗都会消失，不管是确定还是取消。
        listener.OnCenterItemClick(this, view);
    }
}
